home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9757 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  106 lines

  1. Path: news.telepac.pt!usenet
  2. From: vortex@telepac.pt (VORTEX)
  3. Newsgroups: comp.lang.c++
  4. Subject: CRC READING ERROR  HELP PLEASE!!!!
  5. Date: Mon, 04 Mar 1996 07:07:32 GMT
  6. Organization: telepac
  7. Message-ID: <4hdjbo$hab@vivaldi.telepac.pt>
  8. Reply-To: vortex@telepac.pt
  9. NNTP-Posting-Host: por2_p1.telepac.pt
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Hi, could anyone help me doing a modification to this little program,
  13. so that when it occures an CRC reading error i can trap the error and
  14. put my own messagem on the screen, insted of DOS "CRC ERROR READING
  15. DRIVE... ".
  16.  
  17. Thanks, keep in touch with me my e-mail
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. //
  31. //This reading 8 files named SOURCE.1 to SOURCE.8
  32. //& join them together in a final D:\FINAL.EXE
  33. //
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <fcntl.h>
  38. #include <sys\stat.h>
  39. #include <io.h>
  40. #include <stdlib.h>
  41. #include <dos.h>
  42. #include <string.h>
  43.  
  44. #define READ_BYTES (62L * 1024L)
  45.  
  46. void main(void)
  47. {
  48.     char buf[READ_BYTES+1];
  49.     char file_on_disk[16]="source.";
  50.     char filename[129]="d:\\final.exe";
  51.     int f_src, f_dst;
  52.     unsigned int bytes;
  53.     int i, num_disks=8;
  54.     char s1[20],s2[4];
  55.  
  56.  
  57. // Check if destination file exists. If so TRUNCAT to 0 bytes
  58. //                                     If no CREAT a new one with 0 bytes
  59.  
  60.      if((f_dst= creat(filename, S_IWRITE  )) == -1) {
  61.        printf("Cannot open destination file : %s\n",filename);
  62.        exit(1);
  63.      }
  64.  
  65.      close(f_dst);
  66.  
  67.     _dos_creat(filename, O_APPEND, &f_dst);
  68.  
  69.  
  70.    for (i=0;i<num_disks;i++) {
  71.  
  72.     strcpy(s1,file_on_disk);
  73.      itoa(i+1,s2,10);                 // Converts an Integer to a String
  74.       strcat(s1,s2);
  75.  
  76.     if((f_src = open(s1, O_RDONLY | O_BINARY)) == -1) {
  77.      printf("Cannot open source file: %s\n", s1);
  78.       exit(1);
  79.     }
  80.  
  81.  
  82.     printf("Reading : %s\n",s1);
  83.  
  84.  
  85.  
  86. // This is where all the work is done (read from source file
  87. // and write to destination, until done)
  88.  
  89.     while (_dos_read(f_src, buf, READ_BYTES, &bytes)==0) {
  90.       write(f_dst, buf, bytes);
  91.         if (bytes < READ_BYTES) break;
  92.     }
  93.  
  94.      _dos_close(f_src);
  95.  
  96.    }
  97.  
  98. // Close destination file
  99.  
  100.     close(f_dst);
  101.  
  102. }
  103.  
  104.  
  105.  
  106.